package cn.tedu.vue_master.controller;

import cn.tedu.vue_master.mapper.NewUserMapper;
import cn.tedu.vue_master.pojo.spu.vo.SpuListItemVO;
import cn.tedu.vue_master.pojo.user.model.User;
import cn.tedu.vue_master.pojo.user.model.UserEntity;
import cn.tedu.vue_master.restful.JsonResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/testController")
@Slf4j
public class MyController {

    @Value("${vue_master.username}")
    private String username;
    @Value("${vue_master.password}")
    private String password;

    @Autowired
    private NewUserMapper newUserMapper;

    @GetMapping("/testRestTemplate/havePram/{str}")
    public JsonResult<String> printSomethingHavePram(@PathVariable String str) {
        return JsonResult.ok(str);
    }

    @GetMapping("/testRestTemplate/notHavePram")
    public JsonResult<String> printSomethingNotHavePram() {
        return JsonResult.ok("printSomethingNotHavePram");
    }

    @GetMapping("/testRestTemplate/user/{id}")
    public JsonResult<UserEntity> getUserById(@PathVariable("id") String userId) {
        LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.hasText(userId), UserEntity::getUserId, userId);
        UserEntity userEntity = newUserMapper.selectOne(queryWrapper);
        return JsonResult.ok(userEntity);
    }

    @GetMapping("/testRestTemplate/users")
    public JsonResult<List<UserEntity>> listUsers() {
        log.debug("开始处理【根据品牌id获取spu列表】的请求...");
        LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();

        List<UserEntity> list = newUserMapper.selectList(queryWrapper);
        return JsonResult.ok(list);
    }

    @GetMapping("/print")
    public JsonResult<String> print() {
        return JsonResult.ok(username + ", " + password);
    }


}
